import { User } from "./screen//project-list/search-panel";
import {
  accountLoginRequest,
  accountRegisterRequest,
} from "./service/login/index";
const localStorageKey = "__auth_provider";
export interface MjcResponse {
  code?: number;
  message?: string;
  userInfo: User;
}
export const getToken = () => {
  const token = window.localStorage.getItem(localStorageKey);
  if (token) {
    return token;
  } else {
    return undefined;
  }
};
export const handleUserRespinse = (userinfo: User) => {
  window.localStorage.setItem(localStorageKey, userinfo.token || "");
};
export const login = async <mjc>(data: {
  username: string;
  password: string;
}) => {
  try {
    const result = await accountLoginRequest<mjc>(data);
    return result;
  } catch (error) {
    return Promise.reject(error);
  }
};
export const register = async (data: {
  username: string;
  password: string;
}) => {
  try {
    const result = await accountRegisterRequest(data);
    return result;
  } catch (error) {
    return Promise.reject(error);
  }
};
export const loginout = () => {
  window.localStorage.remove(localStorageKey);
};
